package com.runen.infinitemovement.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.runen.infinitemovement.R;
import com.runen.infinitemovement.model.entity.CompanyProgressRankEntity;
import com.runen.infinitemovement.tool.CommonUtil;
import com.runen.infinitemovement.tool.GlideUtils;

public class CompanyProgressRankingAdapter extends BaseQuickAdapter<CompanyProgressRankEntity.DataBean, BaseViewHolder> implements LoadMoreModule {
    private Context context;

    public CompanyProgressRankingAdapter(Context context) {
        super(R.layout.item_company_progress_rank);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CompanyProgressRankEntity.DataBean item) {
        LinearLayout ll_bg1 = helper.getView(R.id.ll_bg1);
        LinearLayout ll_bg = helper.getView(R.id.ll_bg);
        ImageView iv_ranking = helper.getView(R.id.iv_ranking);
        TextView tv_user_name = helper.getView(R.id.tv_user_name);
        TextView tv_ranking = helper.getView(R.id.tv_ranking);
        TextView tv_fire_num = helper.getView(R.id.tv_fire_num);
        tv_user_name.setText(item.name);
        tv_fire_num.setText(CommonUtil.Double2position(item.progress * 100) + "%");
        int position = helper.getAdapterPosition();

        if (position % 2 == 0) {
            ll_bg1.setBackgroundColor(CommonUtil.getColor(R.color.color_FFF9F8F9));
        } else {
            ll_bg1.setBackgroundColor(CommonUtil.getColor(R.color.white));
        }

        switch (position) {
            case 0:
                iv_ranking.setVisibility(View.VISIBLE);
                tv_ranking.setText("0" + (position + 1));
                tv_ranking.setTextColor(CommonUtil.getColor(R.color.white));
                GlideUtils.loadImage(context, CommonUtil.getDrawable(R.mipmap.ico_ranking1), iv_ranking);
                break;
            case 1:
                iv_ranking.setVisibility(View.VISIBLE);
                tv_ranking.setText("0" + (position + 1));
                tv_ranking.setTextColor(CommonUtil.getColor(R.color.white));
                GlideUtils.loadImage(context, CommonUtil.getDrawable(R.mipmap.ico_ranking2), iv_ranking);
                break;
            case 2:
                iv_ranking.setVisibility(View.VISIBLE);
                tv_ranking.setText("0" + (position + 1));
                tv_ranking.setTextColor(CommonUtil.getColor(R.color.white));
                GlideUtils.loadImage(context, CommonUtil.getDrawable(R.mipmap.ico_ranking3), iv_ranking);
                break;
            default:
                ll_bg.setBackground(null);
                tv_ranking.setText((position + 1) + "");
                iv_ranking.setVisibility(View.GONE);
                tv_ranking.setTextSize(20);
                tv_ranking.setTextColor(CommonUtil.getColor(R.color.color_FFDCDCDC));
                break;
        }
    }
}
